﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuantitativeInvestment.Bean;
using QuantitativeInvestment.Tools;

namespace QuantitativeInvestment.Factor
{
    class ApoFactor:Factor
    {
        public ApoFactor()
        {
            this.name = "震荡绝对价";
            Parameter p1 = new Parameter("短期", 12);
            this.paraList.Add(p1.name, p1);

            Parameter p2 = new Parameter("长期", 26);
            this.paraList.Add(p2.name, p2);

            Parameter p3 = new Parameter("天数", 30);
            this.paraList.Add(p3.name, p3);
        }

        public override void addFactorValue(Stock stock)
        {
            int fastPeriod = Int32.Parse(this.paraList["短期"].value.ToString());
            int slowPeriod = Int32.Parse(this.paraList["长期"].value.ToString());
            int period = Int32.Parse(this.paraList["天数"].value.ToString());

            if (!stock.factors.ContainsKey(this.name + this.paraList["短期"].value.ToString() + this.paraList["长期"].value.ToString() + this.paraList["天数"].value.ToString()))
            {
                TaLib lib = new TaLib();

                double[] apoValues = lib.getApo(stock.factors["价格"], fastPeriod, slowPeriod);
                int length = stock.factors["价格"].Length;
 
                
                stock.factors.Add(this.name + this.paraList["天数"].value.ToString() + "Apo", apoValues);
                

            }
        }
    }
}
